import { errorHandler } from "@/lib/utils";
import { NextRequest, NextResponse } from "next/server";
/**
 * 泛型 表示返回值的类型
 */
export function handlerApi<T>(handler: Function) {
  return async (req: NextRequest, ...args: any): Promise<any> => {
    try {
      const result = await handler(req, args);
      return NextResponse.json({
        data: result as T,
        message: "success",
        code: 200,
      });
    } catch (err) {
      return errorHandler(err);
    }
  };
}
